using MicroMsg.Common.Event;
using MicroMsg.Manager;
using MicroMsg.Plugin.Sns.Scene;
using MicroMsg.Resource.@string;
using MicroMsg.Scene;
using MicroMsg.Storage;
using MicroMsg.UI.Page;
using MicroMsg.UI.Util;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Imaging;
namespace MicroMsg.UI.UserContrl
{
	public class AlbumCoverCtrl : SnsHttpImgCtrlBase
	{
		private const string TAG = "AlbumCoverCtrl";
		private Contact mCon;
		private bool bIsCirclePage;
		private static List<string> mHasLikedUsers = new List<string>();
		private ulong objId;
		private string urlObj;
		public SnsInfo snsInfo;
		private CommentType commentType;
		private AddContactScene addContactScene;
		private bool mBIsFirstLoaded = true;
		private bool mBIsCtrlLoaded;
		public bool allowMessageboxShowing = true;
		private EventWatcher mWatchSnsInfo;
		internal Grid AlbumGrid;
		internal Image AlbumCoverImg;
		internal EmojiTextEx NoCoverTipBlock;
		internal EmojiText NickName2Txt;
		internal EmojiText NickNameTxt;
		internal Image HeadImg;
		internal EmojiTextEx sigtureTxt;
		internal Grid panelNewMsgHint;
		internal Grid panelSendFailed;
		private bool _contentLoaded;
		public Contact mContact
		{
			get
			{
				return this.mCon;
			}
			set
			{
				this.mCon = value;
				this.RefreshContactHeadImg();
			}
		}
		public AlbumCoverCtrl(Contact mCon, bool ifCirclePage = false)
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.AlbumCoverCtrl_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.AlbumCoverCtrl_Unloaded));
			this.mContact = mCon;
			this.bIsCirclePage = ifCirclePage;
			this.InitUi(this.bIsCirclePage);
		}
		protected override void ObjectCome(object object_0)
		{
			if (object_0 != null && object_0 is snsMediaDownloadInfo)
			{
				snsMediaDownloadInfo snsMediaDownloadInfo = object_0 as snsMediaDownloadInfo;
				if (snsMediaDownloadInfo.object_0 != null && snsMediaDownloadInfo.object_0 is BitmapImage)
				{
					this.AlbumCoverImg.set_Source(snsMediaDownloadInfo.object_0 as BitmapImage);
					if (this.NoCoverTipBlock.get_Visibility() == null)
					{
						this.NoCoverTipBlock.set_Visibility(1);
					}
				}
				return;
			}
		}
		private void AlbumCoverCtrl_Loaded(object sender, RoutedEventArgs e)
		{
			this.mBIsCtrlLoaded = true;
			this.registerEvent();
		}
		private void AlbumCoverCtrl_Unloaded(object sender, RoutedEventArgs e)
		{
			this.mBIsCtrlLoaded = false;
			if (!this.bIsCirclePage)
			{
				this.unRegisterEvent();
			}
		}
		private void HeadImg_Tap(object sender, GestureEventArgs e)
		{
			if (this.bIsCirclePage)
			{
				object[] passData = new object[]
				{
					this.mContact
				};
				SnsUserMainPage.GoToThisPage(passData);
				return;
			}
			BasePage rootPage = ToolFunction.GetRootPage();
			if (rootPage == null)
			{
				return;
			}
			if (rootPage is SnsUserMainPage)
			{
				SnsUserMainPage snsUserMainPage = rootPage as SnsUserMainPage;
				if (snsUserMainPage.shakePeople != null)
				{
					ToolFunction.GotoPageForUserControl("/Source/Plugin/Shake/UI/ShakePeopleInfo.xaml", new object[]
					{
						snsUserMainPage.shakePeople
					}, false);
					return;
				}
				if (snsUserMainPage.mLbsPeople != null)
				{
					ToolFunction.GotoPageForUserControl("/Source/Plugin/Lbs/UI/LbsPeopleInfo.xaml", new object[]
					{
						snsUserMainPage.mLbsPeople
					}, false);
					return;
				}
				if (this.mContact != null)
				{
					Contact contact = StorageMgr.contact.method_0(this.mContact.strUsrName);
					if (contact != null)
					{
						this.mContact = contact;
					}
				}
				ContactDetailViewForAll.GotoContactDitailView("", "", this.mContact, ContactDetailFromType.FROM_MMCONTACT, false);
			}
		}
		private void AlbumCoverImg_Tap(object sender, GestureEventArgs e)
		{
			if (!this.mBIsCtrlLoaded)
			{
				return;
			}
			BasePage rootPage = ToolFunction.GetRootPage();
			if (rootPage == null)
			{
				return;
			}
			if (rootPage is SnsUserMainPage)
			{
				SnsUserMainPage snsUserMainPage = rootPage as SnsUserMainPage;
				if (snsUserMainPage.bHasMsgboxShown)
				{
					this.allowMessageboxShowing = false;
				}
				else
				{
					this.allowMessageboxShowing = true;
				}
			}
			if (this.mContact == null)
			{
				return;
			}
			if (this.mContact.strUsrName == AccountMgr.getCurAccount().strUsrName)
			{
				if (this.allowMessageboxShowing)
				{
					this.allowMessageboxShowing = false;
					MMMessageBox mMMessageBox = MMMessageBox.Show(strings.Album_ChangeBG_Title, "", true, strings.COM_Yes, strings.COM_No);
					mMMessageBox.ReturnEvent = new DlgReturnEvent(this.ChangeBkDlgReturn);
					return;
				}
			}
			else
			{
				if (this.objId <= 0uL)
				{
					return;
				}
				this.snsInfo = SnsInfoMgr.smethod_0(this.objId);
				if (this.snsInfo == null)
				{
					return;
				}
				bool flag;
				if (this.snsInfo.nLikeFlag == 1)
				{
					flag = true;
				}
				else
				{
					if (AlbumCoverCtrl.mHasLikedUsers == null)
					{
						AlbumCoverCtrl.mHasLikedUsers = new List<string>();
						flag = false;
					}
					else
					{
						flag = AlbumCoverCtrl.mHasLikedUsers.Contains(this.snsInfo.strUserName);
					}
				}
				if (flag)
				{
					MessageBoxManager.ShowToast(strings.Album_Background_HasLiked, 2500, null, false);
					return;
				}
				if (this.allowMessageboxShowing)
				{
					this.allowMessageboxShowing = false;
					MMMessageBox mMMessageBox2 = MMMessageBox.Show(strings.Album_Like_Background, "", true, strings.COM_Yes, strings.COM_No);
					mMMessageBox2.ReturnEvent = new DlgReturnEvent(this.ILikeDlgReturn);
				}
			}
		}
		public void ChangeBkDlgReturn(DlgReturnEventArg dlgReturnEventArg_0)
		{
			if (MMMessageBox.GetUserClickResult(dlgReturnEventArg_0) == 0)
			{
				ToolFunction.GotoPageForUserControl("/Source/Plugin/Sns/Common/UI/AlbumCover/GoChangeAlbumCover.xaml", null, false);
			}
			this.allowMessageboxShowing = true;
		}
		public void ILikeDlgReturn(DlgReturnEventArg dlgReturnEventArg_0)
		{
			if (MMMessageBox.GetUserClickResult(dlgReturnEventArg_0) == 0)
			{
				MessageBoxManager.ShowToast(strings.Album_Like_Btn_Liked, 2500, null, false);
				if (this.snsInfo == null)
				{
					return;
				}
				if (this.mContact == null)
				{
					this.commentType = CommentType.MMSNS_COMMENT_STRANGER_LIKE;
					this.addContactScene = AddContactScene.MM_ADDSCENE_PF_UNKNOWN;
				}
				else
				{
					if (ContactMgr.isContact(this.mContact))
					{
						this.commentType = CommentType.MMSNS_COMMENT_LIKE;
						this.addContactScene = AddContactScene.MM_ADDSCENE_PF_CONTACT;
					}
					else
					{
						this.commentType = CommentType.MMSNS_COMMENT_STRANGER_LIKE;
						if (this.mContact.nSource.get_HasValue())
						{
							this.addContactScene = (AddContactScene)this.mContact.nSource.get_Value();
						}
						else
						{
							this.addContactScene = AddContactScene.MM_ADDSCENE_PF_UNKNOWN;
						}
					}
				}
				if (SnsCommentServiceCenter.snsCommentService == null)
				{
					SnsCommentServiceCenter.init();
				}
				SnsCommentServiceCenter.snsCommentService.doSendComment(this.snsInfo, "", this.commentType, this.addContactScene, null, -1);
				if (AlbumCoverCtrl.mHasLikedUsers == null)
				{
					AlbumCoverCtrl.mHasLikedUsers = new List<string>();
				}
				AlbumCoverCtrl.mHasLikedUsers.Add(this.snsInfo.strUserName);
			}
			this.allowMessageboxShowing = true;
		}
		private void InitUi(bool bIsCirclePage)
		{
			if (this.mContact == null)
			{
				return;
			}
			if (this.mContact.strUsrName == AccountMgr.strUsrName)
			{
				this.HeadImg.set_Source(AccountMgr.getHeadimg());
				this.NickNameTxt.Text = AccountMgr.strNickName;
				this.NickName2Txt.Text = AccountMgr.strNickName;
			}
			else
			{
				this.HeadImg.set_Source(HeadImgMgr.getHeadImage(this.mContact));
				string contactDisplayName = ContactHelper.GetContactDisplayName(this.mContact);
				this.NickNameTxt.Text = contactDisplayName;
				this.NickName2Txt.Text = contactDisplayName;
			}
			if (!bIsCirclePage)
			{
				if (this.mContact.strUsrName == AccountMgr.strUsrName)
				{
					this.sigtureTxt.Text = AccountMgr.getCurAccount().strSignature;
				}
				else
				{
					this.sigtureTxt.Text = this.mContact.strSignature;
				}
				this.sigtureTxt.set_Foreground(R.theme.SNS_ALBUMCOVER_SIGTURE_BRUSH);
				this.sigtureTxt.set_Visibility(0);
			}
			else
			{
				this.sigtureTxt.set_Visibility(1);
			}
			this.RefreshCoverImage();
		}
		public void RefreshContactHeadImg()
		{
			if (this.mContact.strUsrName == AccountMgr.strUsrName)
			{
				this.HeadImg.set_Source(AccountMgr.getHeadimg());
				return;
			}
			this.HeadImg.set_Source(HeadImgMgr.getHeadImage(this.mContact));
		}
		public void RefreshCoverImage()
		{
			if (this.mContact == null)
			{
				return;
			}
			if (this.mContact.strUsrName == AccountMgr.strUsrName)
			{
				if (AccountMgr.getCurAccount().nSnsBGObjectID == 0uL)
				{
					this.AlbumGrid.set_Background(R.theme.SNS_ALBUMCOVER_BK_BRUSH);
					this.NoCoverTipBlock.set_Visibility(0);
					return;
				}
				this.NoCoverTipBlock.set_Visibility(1);
				this.objId = AccountMgr.getCurAccount().nSnsBGObjectID;
				this.urlObj = AccountMgr.getCurAccount().strSnsBGImgID;
			}
			else
			{
				if (this.mContact.nSnsBGObjectID == 0uL)
				{
					this.AlbumGrid.set_Background(R.theme.SNS_ALBUMCOVER_BK_BRUSH);
					this.NoCoverTipBlock.set_Visibility(1);
					return;
				}
				this.NoCoverTipBlock.set_Visibility(1);
				this.objId = this.mContact.nSnsBGObjectID;
				this.urlObj = this.mContact.strSnsBGImgID;
			}
			this.snsInfo = SnsInfoMgr.smethod_0(this.objId);
			if (this.snsInfo == null)
			{
				NetSceneSnsDetail netSceneSnsDetail = new NetSceneSnsDetail();
				netSceneSnsDetail.doScene(this.objId);
			}
			snsMediaDownloadInfo snsMediaDownloadInfo = new snsMediaDownloadInfo
			{
				string_0 = this.urlObj,
				snsObjID = this.objId,
				urlType = SnsUrlType.MMSNS_URL_CDN,
				priority = SnsPriority.HIGH
			};
			base.StartRequest(snsMediaDownloadInfo, true);
			if (snsMediaDownloadInfo.object_0 != null && snsMediaDownloadInfo.object_0 is BitmapImage)
			{
				this.AlbumCoverImg.set_Source(snsMediaDownloadInfo.object_0 as BitmapImage);
			}
		}
		private void registerEvent()
		{
			if (this.mWatchSnsInfo == null)
			{
				this.mWatchSnsInfo = new EventWatcher(this, this, new EventHandlerDelegate(this.OnSnsinfoAddEvent));
				EventCenter.registerEventWatcher(EventConst.ON_STORAGE_SNSINFO_ADD, this.mWatchSnsInfo);
				EventCenter.registerEventWatcher(EventConst.ON_STORAGE_SNSINFO_MODIFY, this.mWatchSnsInfo);
			}
		}
		public void unRegisterEvent()
		{
			if (this.mWatchSnsInfo != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_STORAGE_SNSINFO_ADD, this.mWatchSnsInfo);
				EventCenter.removeEventWatcher(EventConst.ON_STORAGE_SNSINFO_MODIFY, this.mWatchSnsInfo);
				this.mWatchSnsInfo = null;
			}
		}
		private void OnSnsinfoAddEvent(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs == null)
			{
				return;
			}
			List<SnsInfo> listObject = evtArgs.getListObject<SnsInfo>();
			if (listObject != null)
			{
				for (int i = 0; i < listObject.get_Count(); i++)
				{
					TimeLineObject timeLine = SnsInfoMgr.getTimeLine(listObject.get_Item(i));
					if (timeLine != null && timeLine.content.nStyle == 7 && listObject.get_Item(i).strUserName == AccountMgr.strUsrName && timeLine.content.mediaList.get_Item(0).strUrl == AccountMgr.getCurAccount().strSnsBGImgID)
					{
						snsMediaDownloadInfo objReqInfo = new snsMediaDownloadInfo
						{
							string_0 = timeLine.content.mediaList.get_Item(0).strUrl,
							snsObjID = SnsInfo.toID(listObject.get_Item(i).strObjectID),
							urlType = SnsUrlType.MMSNS_URL_CDN,
							priority = SnsPriority.HIGH
						};
						base.StartRequest(objReqInfo, true);
					}
				}
			}
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/Sns/Common/UI/AlbumCover/AlbumCoverCtrl.xaml", 2));
			this.AlbumGrid = (Grid)base.FindName("AlbumGrid");
			this.AlbumCoverImg = (Image)base.FindName("AlbumCoverImg");
			this.NoCoverTipBlock = (EmojiTextEx)base.FindName("NoCoverTipBlock");
			this.NickName2Txt = (EmojiText)base.FindName("NickName2Txt");
			this.NickNameTxt = (EmojiText)base.FindName("NickNameTxt");
			this.HeadImg = (Image)base.FindName("HeadImg");
			this.sigtureTxt = (EmojiTextEx)base.FindName("sigtureTxt");
			this.panelNewMsgHint = (Grid)base.FindName("panelNewMsgHint");
			this.panelSendFailed = (Grid)base.FindName("panelSendFailed");
		}
	}
}
